import Scrollbar from 'smooth-scrollbar';

export default class ScrollbarStyle {

    static tableBody = null;
    static tableHeader = null;

    static initScroll() {
        //console.log('Scrollbar.has(this.tableBody)==',Scrollbar.has(this.tableBody))
        if (!Scrollbar.has(this.tableBody)) {
            this.scrollbarObj = Scrollbar.init(this.tableBody, {
                alwaysShowTracks: false,
            });
            this.addListener();
        }
    }

    static addListener() {
        this.scrollbarObj.addListener((item) => {
            const { offset, limit } = item;
            this.tableHeader.scrollTo(offset.x, 0)
        })
    }

    static removeListener() {
        if (this.scrollbarObj) {
            this.scrollbarObj.destroy(this.tableBody);
            this.scrollbarObj.removeListener();
            this.scrollbarObj = null;
        }
    }
}



//smooth-scrollbar api：https://github.com/idiotWu/smooth-scrollbar/blob/develop/docs/api.md